#ifndef WIDGET_H
#define WIDGET_H
#include <QWidget>
#include <QUdpSocket>
#include <QHostInfo>
#include <QMessageBox>
#include <QTcpSocket>
#include <QListWidgetItem>
#include "addfriend.h"
#include "creategroup.h"
#include "addgroup.h"
QT_BEGIN_NAMESPACE
namespace Ui {
class Widget;
}
QT_END_NAMESPACE
enum MsgType{Msg, UsrEnter, UsrLeft, FileName, Refuse};
enum StateType{BroadCast,Group,Single};
class Widget : public QWidget
{
    Q_OBJECT

public:
    Widget(QWidget *parent,QString usrname);
    ~Widget();
    QTcpSocket *tcpClient;
    QString getLocalIP();
private slots:


    void on_cleartoolButton_clicked();//清空聊天记录

    void on_sendpushButton_clicked();//发送消息

    void on_exitpushButton_clicked();//退出登录
    void processPendingDatagrams();//接收对方发来的UDP数据报

    void on_modecomboBox_currentIndexChanged(int index);
    void on_groupselectcomboBox_currentIndexChanged(int index);

    void on_addfriend_pushButton_clicked();

    void on_creategroup_pushButton_clicked();

    void on_addgroup_pushButton_clicked();

    void on_editprofile_pushButton_clicked();

    void on_loadmoremsg_pushButton_clicked();

    void on_friend_listWidget_itemClicked(QListWidgetItem *item);

    void on_friend_listWidget_itemDoubleClicked(QListWidgetItem *item);

    void on_group_listWidget_itemClicked(QListWidgetItem *item);

    void on_group_listWidget_itemDoubleClicked(QListWidgetItem *item);
public slots:
    void on_refresh_pushButton_clicked();

protected:
    void closeEvent(QCloseEvent *);//用户退出
private:
    Ui::Widget *ui;
    QUdpSocket *udpSocket;
    qint16 port;
    QString uName;
    QHostAddress groupAddr;
    StateType chatType;//当前的信息是私聊还是群聊还是广播
    QString fileName;
//    Server *srv;//用于文件传输
    QString getIP();//获取本机地址
    QString getUsr();//获取本机的用户的名字

    //子界面
    AddFriend *addfriend;
    Creategroup *creategroup;
    Addgroup *addgroup;
    void usrEnter(QString usrName,QString ipAddr);
    void sendbroadcastmsg(MsgType type);
    void sendmsg();
    void sendgroupmsg();



};
#endif // WIDGET_H
